$(function(){
	/*获取文章信息*/
	var articleXq=JSON.parse(window.localStorage.getItem("articleXq"));
	console.log(articleXq)
	function isDZ(){
		// var count=$('#dianzan').children()[0].children[0].children[1].innerText;
		// 			var imgSrc=$('#dianzan').children()[0].childNodes[1].childNodes[0].firstChild.attributes[0].nodeValue;
		// 			if(articleXq.exchange.state===1){
		// 				imgSrc='./../img/icon-active-dianzan.png'
		// 				$('#dianzan').children()[0].childNodes[1].childNodes[0].firstChild.attributes[0].nodeValue=imgSrc;
		// 			}else if(articleXq.exchange.state===0){
		// 				imgSrc='./../img/icon-dianzan.png'
		// 				count--;
		// 				$('#dianzan').children()[0].children[0].children[1].innerText=count;
		// 				$('#dianzan').children()[0].childNodes[1].childNodes[0].firstChild.attributes[0].nodeValue=imgSrc;
		// 			}
	}
	function getArticle(){
		isDZ();
		/*判断有无标题*/
		var title="";
		var title1="";
		var thoughCount="";
		var anserHTML="";
		var ohterAnswer="";
		for (var i = 0; i < articleXq.ymAnswerVOS.length; i++) {
			// if(articleXq.ymAnswers[i].parentId!==0){
			// 	ohterAnswer+="<div class='article-reply'>"+
			// 	      		 "<p>呵呵呵~</p>"+
			// 	      		 "</div>";
			// }else{
			// 	ohterAnswer="";
			// }
			anserHTML+="<div class='problem-talk-tab'>"+
				      "<div class='person-tab-head'>"+
				  	  //"<div class='head-image'><img src='"+articleXq.ymAnswers[i].headimgurl+"' /></div>"+
					  "<div class='person-name'>"+
					  "<p class='person-name-text'>"+
					  "<span>"+articleXq.ymAnswerVOS[i].userName+"</span>"+
					  "<span><img src='' alt=''></span>"+
					  "</p>"+
					  "<p class='person-reply-time'>"+articleXq.ymAnswerVOS[i].createTimeString+"</p>"+
					  "</div>"+
				      "</div><div class='problem-reply'>"+
				      "<p><span></span>"+articleXq.ymAnswerVOS[i].answerDes+"</p>"+
				      "</div>";
				      "<div class='fgx'></div>"+
				      "<div class='article-tab-foot'>"+
				  	  "<div class='article-pinlun'><a href='javascript:void(0)'' title=''><span><img src='./../img/icon-pinglun.png' alt=''></span><span> 回复 </span></a></div>"+
				      "</div>"+
			          "</div>";
		}
		$('.pinlun-tab').append(anserHTML);
		if(articleXq.title===undefined){
			title+="<a href='#title-link' class=''>关于我们</a>";
			title+="";
			$('.am-header-title').append(title);
			$('.article-tab-title').append(title1);
		}else{
			title+="<a href='#title-link' class=''>"+articleXq.title+"</a>";
			title1+="<h2"+articleXq.title+"</h2>";
			$('.am-header-title').append(title);
			$('.article-tab-title').append(title1);
		}
		/*判断是否有浏览总数*/
		if(articleXq.thoughCount===undefined){
			thoughCount+="";
			$('#thoughtCount').append(thoughCount);
		}else{
			thoughCount+="<p><span><img src='./../img/eyes.png' alt=''></span><span> 4321 </span></p>";
			$('#thoughtCount').append(thoughCount);
		}
		
		$('#creatTime').html(articleXq.create_time);
		$('.article-tab-desc').html(articleXq.article_datail);
		$('#dzCount').html(articleXq.likeNumber);
		$('#pinlunCount,.punlun-count-num').html(articleXq.replyNumber);
		if(articleXq){

		}
	}
	getArticle();
	/*添加评论*/
	$('.am-navbar-nav #insert-pinlun').click(function(){
		$('.pinlun-input textarea').attr('placeholder','添加评论：');
		$('.add-pinlun').css({'display':'block'});
		$('.navbar .am-navbar-nav').css({'display':'none'});
	})
	
	$('body').click(function(){
		console.log($('.add-pinlun').css('display'))
		// if($('.add-pinlun').css('display')=='block'){
		// 	$('.add-pinlun').css({'display':'none'});
		// }else{
		// 	$('.add-pinlun').css({'display':'block'});
		// }
	})
	/*回复评论*/
	$('.article-pinlun').click(function(){
		var curTab=$(this).parent().parent().children();
		var persoName=curTab[0].children[1].children[0].innerText;
		$('.pinlun-input textarea').attr('placeholder','回复'+persoName+'：');
		$('.add-pinlun').css({'display':'block'});
		$('.navbar .am-navbar-nav').css({'display':'none'});
	})
	/*点赞*/
	$('#dianzan').click(function(){
		isDZ();
		ym.ajax({
            url: "/communication/addPraise",
            param:{
                praiseType:'3',
                praiseTypeId:articleXq.exchange.exchangeId,
                userId:'1'
            },
            success: function (data) {
               var newData=JSON.parse(data);
               if (newData.res==1) {
               	ym.ajax({
	            url: "/communication/quertCommunicationDetail",
	            param:{
	                exchangeId:articleXq.exchange.exchangeId
	            },
	            success: function (data) {
	               var newData=JSON.parse(data);
	               if (newData.obj) {
	                  var jsonData=newData.obj[0];
	                  articleXq=JSON.stringify(jsonData);
	                  console.log(articleXq)
	                }
	            }
	            });
                }
            }
            });
	})
	/*收藏*/
})